/* still need to test threads dunno how to do that man...*/
package csel.model;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 

public class AreaEffectTester extends TestCase{

	TimedEffect areaEffect;
	Entity e;

	public static void main(String args[]) 
	{ 
		junit.textui.TestRunner.run(MapTester.class); 
	} 

	@Before
	protected void setUp() throws Exception
	{
		e = new Entity(new GameGlobals(), new Summoner()); 
	}

	//do all of them at once because I'm lazy
	@Test
	public void testAreaEffect()
	{
		int rate = 2;

		areaEffect = new HurtPlayer(rate);
		int damage = e.getLifeLeft();
		areaEffect.doEffect(e); 	//hahahahahaahaha
		Assert.assertEquals(damage+rate, e.getLifeLeft());

		areaEffect = new HealDamage(rate);
		damage = e.getLifeLeft();
		areaEffect.doEffect(e); 	//hahahahahaahaha
		Assert.assertEquals(damage-rate, e.getLifeLeft());

		//eh I don't feel like making a thread...

		InstantDeath iD = new InstantDeath();
		int lives = e.getLives();
		iD.enter(e);		//whahahaahahaha ha  ha
		if(lives > 0)
		{
			lives--;
		}

		Assert.assertEquals(lives, e.getLives());
		Assert.assertEquals(0, e.getLifeLeft());

		int level = e.getLevel();
		LevelUp lu = new LevelUp();
		lu.enter(e);
		Assert.assertEquals(level+1, e.getLevel());

	}

	@Test
	public void testTimedAreaEffect()
	{
		Entity e = new Entity(new GameGlobals(), new Smasher());
		int rate = 2;

		TimedEffect t = new HurtPlayer(rate);

		int dam = e.getLifeLeft();
		
		t.enter(e);

		try
		{
			Thread.sleep(2500);
		} catch (InterruptedException e1)
		{
			e1.printStackTrace();
		}

		t.leave(e);

		Assert.assertEquals(dam+(2*rate), e.getLifeLeft());
		dam = e.getLifeLeft();
		TimedEffect t2 = new HealDamage(rate);

		t2.enter(e);

		try
		{
			Thread.sleep(2500);
		} catch (InterruptedException e1)
		{
			e1.printStackTrace();
		}

		t2.leave(e);

		Assert.assertEquals(dam-(2*rate), e.getLifeLeft());
	}

	@After protected void tearDown() throws Exception 
	{ 
		super.tearDown();
		e = null;
	} 
}
